/**
 * Created by Administrator on 2017/1/13.
 */

global.logger = require('pomelo-logger').getLogger('game');
var roomManager = require('./roomManager');
var utilRedis = require('../../util/redis.js');
global.Redis = null;

module.exports = {
    init: function() {

        async.series([
            function(cb) {
                utilRedis.loadDB(function(err, client) {
                    global.Redis = client;
                    cb(err);
                });
            }
        ], function(err) {
            if (err) {
                logger.error(util.format("game init failed: %j", err));
                process.exit(-1);
            }

            roomManager.registerTimer();
        });
    },

    stop: function(callback) {
        async.series([
            function(cb) {
                if (Redis) {
                    Redis.end();
                }
                cb();
            },
        ], function(err) {
            logger.info('game stop success');
            callback && callback();
        });
    }
}